home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5.2 / dcmds / C Samples / Vbl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  3.7 KB  |  180 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        VBL.c
  3.  
  4.     Contains:    A dcmd which displays onboard and slot-based VBL tasks.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglas
  9.  
  10.     Copyright:    © 1988, 1993-1994 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <3>   11-Dec-94    JM3        Updated for new version 3 dcmd requirements. Removed the remnants of Dave's
  15.                                      old wiggy brace style. Luckily, that habit has long since been broken. :-)
  16.          <2>      9/9/93    DAL        now displays all nonempty SlotVBL queues as well as the regular
  17.                                     VBL queue; cleaned up the output
  18.  
  19.     Modification history:
  20.          2Dec88 sad        written from VCB.
  21.  
  22.     The following MPW commands will build the dcmd and copy it to the
  23.     "Debugger Prefs" file in the System folder. The dcmd's name in
  24.     MacsBug will be the name of the file built by the Linker.
  25.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  26.     C Samples folder into this folder.
  27.  
  28.     C Put.c
  29.     C VBL.c
  30.     Link dcmdGlue.a.o VBL.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o VBL
  31.     BuildDcmd VBL 1001
  32.     Echo 'include "VBL";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  33. */
  34.  
  35. /*
  36.     TO DO
  37.     -----
  38.     identify the task's owner in some way
  39. */
  40.  
  41. #include <Memory.h>
  42. #include <OSUtils.h>
  43. #include <Retrace.h>
  44. #include <Types.h>
  45.  
  46. #include "dcmd.h"
  47. #include "put.h"
  48.  
  49. #define VBLQueue ((QHdrPtr)0x160)
  50.  
  51.  
  52. static void DrawVBL(VBLTask* vblp)
  53. {
  54.  
  55.     PutUHexZTo((unsigned long)vblp,8,8);
  56.     PutSpacesTo(10);
  57.     PutUHexWord(vblp->vblCount);
  58.     PutSpacesTo(17);
  59.     PutUHexWord(vblp->vblPhase);
  60.     PutSpacesTo(24);
  61.     PutUHexZTo((unsigned long)vblp->vblAddr,8,27);
  62.     PutLine();
  63.  
  64. }
  65.  
  66.  
  67. void DumpOneVBLQueue(QHdrPtr theQueue, short slotNum, dcmdBlock* paramPtr)
  68. {
  69.  
  70.     VBLTask* vblp;
  71.     int numvbls = 0;
  72.  
  73.     PutLine();
  74.     PutPStr("\pVBL tasks");
  75.     if(slotNum != -1)
  76.     {
  77.         PutPStr("\p for slot ");
  78.         PutUDec(slotNum);
  79.     }
  80.  
  81.     if (theQueue->qFlags & 0x4000)
  82.         PutPStr("\p (queue executing)");
  83.     else
  84.         PutPStr("\p (queue not executing)");
  85.     PutLine();
  86.  
  87.     vblp = (VBLTask*)(theQueue->qHead);
  88.  
  89. //                             1         2         3         4         5         6         7
  90. //                    1234567890123456789012345678901234567890123456789012345678901234567890
  91.     dcmdDrawLine("\p VBLTask  Count  Phase  Code");
  92.     dcmdDrawLine("\p -------  -----  -----  ----");
  93.  
  94.     while (vblp)
  95.     {
  96.         DrawVBL(vblp);
  97.         numvbls++;
  98.         if (paramPtr->aborted) break;
  99.         if (vblp->qLink == 0)
  100.             if (vblp != (VBLTask*)(theQueue->qTail))
  101.                 dcmdDrawLine("\pVBL queue does not end at VBLQueue.qTail");
  102.         vblp = (VBLTask*)vblp->qLink;
  103.     }
  104.  
  105.     PutUDec(numvbls);
  106.     if(numvbls==1)
  107.         PutPStr("\p VBL task");
  108.     else
  109.         PutPStr("\p VBL tasks");
  110.     PutLine();
  111.  
  112. }
  113.  
  114.  
  115. short GetQueueSize(QHdrPtr theQueue)
  116. {
  117.  
  118.     VBLTask* vblp;
  119.     int count = 0;
  120.  
  121.     vblp = (VBLTask*)(theQueue->qHead);
  122.  
  123.     while (vblp)
  124.     {
  125.         count++;
  126.         if(count>1000)
  127.             return count;    // avoid infinite loop if queue is hosed
  128.         vblp = (VBLTask*)vblp->qLink;
  129.     }
  130.  
  131.     return count;
  132.  
  133. }
  134.  
  135.  
  136. pascal void CommandEntry(dcmdBlock* paramPtr)
  137. {
  138.  
  139.     static const char usageStr[] = "\p";
  140.  
  141.     switch (paramPtr->request)
  142.     {
  143.         case dcmdInit:
  144.             break;
  145.  
  146.         case dcmdHelp:
  147.             dcmdDrawLine("\pLists tasks in the regular and slot VBL queues.");
  148.             break;
  149.  
  150.         case dcmdGetInfo:
  151.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  152.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  153.             break;
  154.  
  155.         case dcmdDoIt:
  156.         {
  157.             short slotNum;
  158.             QHdrPtr *slotQueueArray = *(QHdrPtr **)0x0D04;
  159.             
  160.             dcmdSwapWorlds();
  161.  
  162.             DumpOneVBLQueue(VBLQueue,-1,paramPtr);
  163.             for(slotNum=0; slotNum<=14; slotNum++)
  164.             {
  165.                 if(GetQueueSize(slotQueueArray[slotNum]))
  166.                     DumpOneVBLQueue(slotQueueArray[slotNum], slotNum, paramPtr);
  167.             }
  168.  
  169.             dcmdSwapWorlds();
  170.         }
  171.             break;
  172.  
  173.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  174.  
  175.         default:
  176.             break;
  177.     }
  178.  
  179. }
  180.